package ruanjian.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ruanjian.domain.Customer;
import ruanjian.service.CService;

import java.util.List;

@Controller
@RequestMapping("/customer")
public class CController {
    @Autowired
    private CService cService;
  @RequestMapping("/list.action")
    public String list(Model model){
      List<Customer> customers = cService.selectCus();
      model.addAttribute("page",customers);
      return "customers";

  }
  @RequestMapping("/creatCus.action")
  @ResponseBody
    public  String creatCus(Customer customer){
      int i = cService.creatCus(customer);
      if (i >0 ){
          return "OK";
      }else {
          return "FAIL";
      }
  }
 @RequestMapping("/getCusid.action")
    @ResponseBody
    public Customer getCusid(Integer id){
     Customer cusid = cService.getCusid(id);
     return cusid;
 }
 @RequestMapping("/updateCus.action")
 @ResponseBody
 public String UpdateCus(Customer customer){
     int i = cService.updateCus(customer);
     if(i>0){
         return "OK";
     }else {
         return "FAIL";
     }
 }
 @RequestMapping("/deleteCus.action")
    @ResponseBody
    public String deleteCus(Integer id){
     int i = cService.deleteCus(id);
     if (i>0){
         return "OK";
     }else {
         return "FAIL";
     }
 }
}
